package com.dsp.dubbo.demo.consumer;

import com.dsp.dubbo.demo.api.AssetFreezeService;
import com.dsp.dubbo.demo.api.AssetService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.math.BigDecimal;

@SpringBootApplication
public class ConsumerApplication {

    @DubboReference(version = "1.0.0", tag = "red")
    private AssetService assetService;

    @DubboReference(version = "1.0.0", tag = "red")
    private AssetFreezeService assetFreezeService;

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }

    @Bean
    public ApplicationRunner runner() {
        return args -> {
            long num = assetService.findAmountByUserId(1L);
            System.out.println("findAmountByUserId from server: " + num);
            int result = assetFreezeService.freezeByUserId(1L, new BigDecimal(100));
            System.out.println("freezeByUserId from server：" + result);
        };
    }
}
